testtable:
  type: table
  displayName: Test table
  order: '10'
  primaryKey: ID
  scheme:
    columns:
    - ID:
        type: KEYTYPE
        autoIncrement: true
        primaryKey: true
    - name:
        type: VARCHAR(20)
    - value:
        canBeNull: true
        type: INT
  queries:
  - '*** Selection view ***':
      type: 1D
      operations: Filter
      code: SELECT ID AS "Code", name AS "Name" FROM testtable
  - 'Quick Filter: Test groovy':
      type: Groovy
      invisible: true
      file: queries.test.QuickFilter.groovy
  - 'Quick Filter: Test yes/no tags':
      type: 1D_unknown
      invisible: true
      code: |
            SELECT 'yes'
            UNION ALL
            SELECT 'no'
  - 'Quick Filter: Test name':
      type: 1D_unknown
      invisible: true
      code: |
            SELECT DISTINCT name
            FROM testtable
            ORDER BY name
  - 'Quick Filter: Test value':
      type: 1D_unknown
      invisible: true
      code: |
          SELECT value,
            CASE
              WHEN value = 1
              THEN 'value 1'
              ELSE 'value 2'
            END
          FROM testtable
          ORDER BY value
  - Test 1D:
      type: 1D
      roles: [Administrator, Guest]
      layout: '{"topForm":"TopFilter"}'
      defaultView: true
      operations:
      - Delete
      - Edit
      - Insert
      - TestReloadButtonOperation
      - TestOperation
      - TestVerticalOperation
      - TestDownloadOperation
      - TestGroupOperation
      - TestLongTimeOperation
      - TestNestedDpsOperation
      - TestTabedOperation
      - TestUploadOperation
      - AddRemoveCategory
      - Filter
      - TopFilter
      - CustomFilter
      code: |2-
            SELECT
              t.ID AS "___ID",
              t.name AS "Name",
              '<quick visible="true"/>;<link using="___ID" columns="ID" table="testtable" queryName="Test 1D unknown"/>'
                AS ";Name",
              t.value AS "Value",
              'pretty json format' AS "JSON",
              '<quick visible="false"/>;<link columns="_displayType_,_prettyJson_" using="json,yes" table="testtable" queryName="Test 1D"/>'
              AS ";JSON"
            FROM
              testtable t
            WHERE 1=1
              <if parameter="name">
                AND t.name = '<parameter:name/>'
              </if>
              <if parameter="value">
                AND t.value = '<parameter:value/>'
              </if>
  - Test 1D unknown:
      type: 1D_unknown
      invisible: true
      roles: [Administrator, Guest]
      operations:
      - CustomFilter
      code: |2-
            SELECT
              t.name AS "Name",
              t.value AS "Value"
            FROM
              testtable t
            WHERE (1=1)
            <if parameter="ID">
              AND t.ID IN <parameter:ID multiple="true" refColumn="testtable.ID"/>
            </if>
  - Test quick filters:
      type: 1D_unknown
      roles: [Administrator, Guest]
      quickFilters:
        By name query:
          queryParam: name
          targetQueryName: 'Quick Filter: Test name'
        By name fake table:
          queryParam: name
          targetQueryName: 'Quick Filter: Test yes/no tags'
        By name from groovy:
          queryParam: name
          targetQueryName: 'Quick Filter: Test groovy'
        By value:
          queryParam: value
          targetQueryName: 'Quick Filter: Test value'
      code: <@_copyQuery "Test 1D"/>
  - Test JSON format:
      type: 1D_unknown
      roles: [Administrator, Guest]
      layout: '{"_displayType_":"json"}'
      code: |2-
            SELECT
              t.name AS "Name",
              t.value AS "Value"
            FROM
              testtable t
            WHERE (1=1)
            <if parameter="ID">
              AND t.ID IN <parameter:ID multiple="true" refColumn="testtable.ID"/>
            </if>
  - Test 1D quickvisible as select:
      type: 1D
      roles: [Administrator, Guest]
      layout: '{"topForm":"TopFilter","quickType":"select"}'
      defaultView: true
      operations:
        - TopFilter
      code: |2-
            SELECT
              t.ID AS     "___ID",
              t.name AS  "Name 1",
              '<quick visible="true"/>;<link using="___ID" columns="ID" table="testtable" queryName="Test 1D unknown"/>' AS ";Name 1",
              t.value AS "Value 1;<quick visible='false'/>",
              t.name AS  "Very long name long long long 2;<quick visible='true'/>",
              t.value AS "Value 2;<quick visible='false'/>",
              t.name AS  "Name 3;<quick visible='true'/>",
              t.value AS "Value 3;<quick visible='false'/>",
              t.name AS  "Name 4;<quick visible='true'/>",
              t.value AS "Value 4;<quick visible='false'/>",
              t.name AS  "Name 5;<quick visible='true'/>",
              t.value AS "Value 5;<quick visible='false'/>",
              t.name AS  "Name 6;<quick visible='true'/>",
              t.value AS "Value 6;<quick visible='false'/>",
              t.name AS  "Name 7;<quick visible='true'/>",
              t.value AS "Value 7;<quick visible='false'/>",
              t.name AS  "Name 8;<quick visible='true'/>",
              t.value AS "Value 8;<quick visible='false'/>",
              t.name AS  "Name 9;<quick visible='true'/>",
              t.value AS "Value 9;<quick visible='false'/>",
              t.name AS  "Name 10",
              t.value AS "Value 10",
              t.name AS  "Name 11;<quick visible='true'/>",
              t.value AS "Value 11;<quick visible='false'/>"
            FROM
              testtable t
  - Test Chart:
      type: 1D_unknown
      roles: [Administrator, Guest]
      layout: '{"defaultPageLimit": 10000,"type":"chart", "xData":"column1", "yData":"column2,column4"}'
      code: |2-
            WITH
              data AS (
                  SELECT 1 AS y
                  UNION ALL
                  SELECT 2 AS y
                  UNION ALL
                  SELECT 3 AS y
                  UNION ALL
                  SELECT 4 AS y
                  UNION ALL
                  SELECT 5 AS y
                  UNION ALL
                  SELECT 6 AS y
                  UNION ALL
                  SELECT 7 AS y
                  UNION ALL
                  SELECT 8 AS y
                  UNION ALL
                  SELECT 9 AS y
                  UNION ALL
                  SELECT 10 AS y
                  UNION ALL
                  SELECT 10 AS y
                  UNION ALL
                  SELECT 11 AS y
                  UNION ALL
                  SELECT 12 AS y
                  UNION ALL
                  SELECT 13 AS y
                  UNION ALL
                  SELECT 14 AS y
                  UNION ALL
                  SELECT 15 AS y
                  UNION ALL
                  SELECT 16 AS y
                  UNION ALL
                  SELECT 17 AS y
                  UNION ALL
                  SELECT 18 AS y
                  UNION ALL
                  SELECT 19 AS y
                  )
            SELECT
              t.y AS "column1",
              t.y AS "column2",
              '<chart mode="lines+markers" name="Title from column attr" line="{width:1;color:RGB(100,200,200)}" />' AS  ";column2",
              t.y * 2 AS "column3",
              CASE WHEN t.y < 10 THEN  t.y * 3 ELSE t.y * 2 END AS "column4"
            FROM data t
  - subQuery:
      type: 1D_unknown
      invisible: true
      roles: [Administrator, Guest]
      code: |2-
          SELECT
            t.name,
            '<sql beautifierName="json">
              SELECT
                u.name AS "name",
                u.value AS "value"
              FROM testtable u order by id limit 3
            </sql>' AS "test"
          FROM testtable t
  - subQuery3:
      type: 1D_unknown
      invisible: true
      roles: [Administrator, Guest]
      code: |2-
          SELECT
            t.name,
            '<sql beautifierName="json">
              SELECT
                u.name AS "name",
                '<sql beautifierName="line">
                   SELECT CONCAT('(', u.name, ' - ', u.value, ')') AS "test"
                   FROM testtable u order by id limit 3
                </sql>' AS "test2"
              FROM testtable u order by id limit 3
            </sql>' AS "test"
          FROM testtable t
  operations:
  - TestOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm","order":10}'
      file: operations.test.TestOperation.groovy
  - TestVerticalOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"verticalForm"}'
      file: operations.test.TestOperation.groovy
  - CustomFilter:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm"}'
      file: operations.test.CustomFilter.groovy
  - TestDownloadOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm"}'
      file: operations.test.TestDownloadOperation.groovy
  - TestGroupOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm","order":6}'
      file: operations.test.TestGroupOperation.groovy
  - TestLongTimeOperation:
      type: Groovy
#      layout: '{"type":"modalForm","_longTimeOp_":"yes"}'
      layout: '{"_longTimeOp_":"yes"}'
      roles: Administrator
      file: operations.test.TestLongTimeOperation.groovy
  - TestReloadButtonOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm","order":7}'
#      layout: '{"type":"verticalForm"}'
      file: operations.test.TestReloadButtonOperation.groovy
  - TestNestedDpsOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm","order":8}'
      file: operations.test.TestNestedDpsOperation.groovy
  - TestTabedOperation:
      type: Groovy
      roles: Administrator
#      layout: '{"type":"modalForm"}'
      file: operations.test.TestTabedOperation.groovy
  - TestUploadOperation:
      type: Groovy
      roles: Administrator
      layout: '{"type":"modalForm","order":4}'
      file: operations.test.TestUploadOperation.groovy
  - Delete:
      records: 2
      roles: Administrator
      layout: '{"type":"modalForm"}'
      code: com.developmentontheedge.be5.server.operations.DeleteOperation
  - Edit:
      records: 1
      roles: Administrator
      code: com.developmentontheedge.be5.server.operations.SilentEditOperation
  - Insert:
      roles: Administrator
      code: com.developmentontheedge.be5.server.operations.SilentInsertOperation
  - Filter:
      roles: Administrator
      layout: '{"type":"modalForm"}'
      code: com.developmentontheedge.be5.server.operations.FilterOperation
  - TopFilter:
      roles: '@AllRoles'
      code: com.developmentontheedge.be5.server.operations.FilterByParamsInQueryOperation
  - AddRemoveCategory:
      records: 2
      roles: Administrator
      code: com.developmentontheedge.be5.modules.core.operations.categories.AddRemoveCategory
